local hx__jijin = fk.CreateSkill {
  name = "hx__jijin",
}

hx__jijin:addEffect(fk.CardUsing, {
  can_trigger = function(self, event, target, player, data)
    return data.from == player and player:hasSkill(hx__jijin.name) and player.phase == Player.Play and
      (data.extra_data or {}).hx__jijin_triggerable
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, hx__jijin.name)
  end,
})
hx__jijin:addEffect(fk.CardUsing, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__jijin.name) and player.phase == Player.Play
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if player:hasMark("@hx__jijin_record-phase") then
      if data.card:getSuitString() ~= player:getMark("hx__jijin_suit-phase") or
          (data.card.number ~= player:getMark("hx__jijin_number-phase") and data.card.number ~= 0) then
        data.extra_data = data.extra_data or {}
        data.extra_data.hx__jijin_triggerable = true
      end
      if data.card.suit == Card.NoSuit then
        room:setPlayerMark(player, "hx__jijin_suit-phase", 0)
      else
        room:setPlayerMark(player, "hx__jijin_suit-phase", data.card:getSuitString())
      end
    end
    room:setPlayerMark(player, "hx__jijin_number-phase", data.card.number)
    room:setPlayerMark(player, "@hx__jijin_record-phase", {data.card:getSuitString(true), data.card:getNumberStr()})
  end,
})

return hx__jijin